<?
error_reporting(E_ALL);
require_once("lang.php");

$start_time = microtime_float();

//ob_start("callback");

//Đếm số lượng người truy cập
$db_visited	= new db_execute("UPDATE visited SET vis_counter = vis_counter + 1");
unset($db_visited);

$module = getValue('module', 'str', 'GET', 'news');

$iCat = getValue('iCat');
if ($iCat > 0)
{
	$db_cat = new db_query('SELECT * FROM categories_multi WHERE cat_id = ' . $iCat . ' AND lang_id = ' . $lang_id);
	$current_cat = mysql_fetch_array($db_cat->result);
	unset($db_cat);
	
	if (!$current_cat)
	{
		redirect($con_root_path . 'notfound.html');
	}
}

$sqlWhere = '';
if ($current_cat)
{
	$sqlWhere .= ' AND cat_id IN (' . $current_cat['cat_all_child'] . ') ';
}
else
{
	if ($iCat > 0)
	{
		$sqlWhere .= ' AND cat_id = ' . $iCat . ' ';
	}
}
$sqlOrderBy = 'new_date DESC';
//Get page break params
$page_size		= 10;
$page_prefix	= tdt('Trang') . ": ";
$normal_class	= "page";
$selected_class= "page_current";
$previous		= "<";
$next				= ">";
$first			= "<<";
$last				= ">>";
$break_type		= 1;//"1 => << < 1 2 [3] 4 5 > >>", "2 => < 1 2 [3] 4 5 >", "3 => 1 2 [3] 4 5", "4 => < >"
$url				= getURL(0,1,1,1,"page");
$db_count		= new db_query("SELECT COUNT(*) AS count
										 FROM (categories_multi, news_multi) INNER JOIN news_hits ON new_id = nh_id
									 	 WHERE cat_id = new_category_id AND categories_multi.lang_id = " . $lang_id . $sqlWhere);
$listing_count	= mysql_fetch_array($db_count->result);
$total_record	= $listing_count["count"];
$current_page	= getValue("page", "int", "GET", 1);
if($total_record % $page_size == 0) $num_of_page = $total_record / $page_size;
else $num_of_page = (int)($total_record / $page_size) + 1;
if($current_page > $num_of_page) $current_page = $num_of_page;
if($current_page < 1) $current_page = 1;
$db_count->close();
unset($db_count);
//End get page break params
$db_listing	= new db_query("SELECT *
									 FROM (categories_multi, news_multi) INNER JOIN news_hits ON new_id = nh_id
									 WHERE cat_id = new_category_id AND categories_multi.lang_id = " . $lang_id . $sqlWhere . "
									 ORDER BY " . $sqlOrderBy . "
									 LIMIT " . ($current_page - 1) * $page_size . ", " . $page_size);

$site_title = tdt('Tin_tuc') . ' | ' . $con_site_title;
if ($current_cat['cat_name'])
{
	$site_title = $current_cat['cat_name'] . ' | ' . $site_title;
}

if ($current_page > 1)
{
	$site_title .= ' | ' . tdt('Trang') . ' ' . $current_page;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="keywords" content="<?=str_replace("\n", "", htmlspecialchars($con_meta_keywords))?>">
<meta name="description" content="<?=str_replace("\n", "", htmlspecialchars($con_meta_description))?>">
<link href="<?=$gs_imagepath?>favicon.ico" rel="icon" type="image/x-icon" />
<link href="<?=$gs_imagepath?>favicon.ico" rel="shortcut icon" />
<title><?=$site_title?></title>
<style type="text/css" media="all">@import "<?=$theme_csspath?>main.css";</style>
<style type="text/css" media="all">@import "<?=$theme_csspath?>thickbox.css";</style>
<style type="text/css" media="all">@import "<?=$theme_imagepath?>theme.css";</style>
</head>
<body<?=$body_style?>>
<div id="body"<?=$div_id_body_style?>>
	<div id="container_body">
    	<div id="container_header"><? include($real_path . "includes/inc_header.php");?></div>
        <div id="container_content">
        	<div id="container_content_left">
			<?
			include($real_path . "includes/inc_module_left_menu_news.php");
			include($real_path . "includes/inc_module_online_support.php");
			include($real_path . "includes/inc_module_left_banner.php");
			include($real_path . "includes/inc_module_statistic.php");
			?>
            </div>
            <div id="container_content_center">
            <?
			include($real_path . "includes/inc_module_center_search_form.php");
            include($real_path . "includes/inc_type_news.php");
			?>
            </div>
            <div id="container_content_right">
            <?
			include($real_path . "includes/inc_module_hot_news.php");
			include($real_path . "includes/inc_module_right_banner.php");
			?>
            </div>
        	<div class="clear"></div>
        </div>
    	<div id="container_footer"><? include($real_path . "includes/inc_footer.php");?></div>
    </div>
</div>
</body>
</html>
<?
//ob_end_flush();
?>